require 'osx/cocoa'

class MyDocument < OSX::NSDocument
  ib_outlets :documentView, :left_margin
  attr_reader :pdf

  def windowNibName
    # Override returning the nib file name of the document If you need
    # to use a subclass of NSWindowController or if your document
    # supports multiple NSWindowControllers, you should remove this
    # method and override makeWindowControllers instead.
    return "MyDocument"
  end

  def windowControllerDidLoadNib(aController)
    super_windowControllerDidLoadNib(aController)
    # Add any code here that need to be executed once the
    # windowController has loaded the document's window.
    @documentView.resetMargins
  end

  def loadDataRepresentation_ofType(data, aType)
    @pdf = PDFDocument.alloc.initWithData(data)
    return true
  end

  def printOperationWithSettings_error(printSettings, outError)
    NSPrintOperation.printOperationWithView_printInfo(@documentView, self.printInfo)
  end

  def shouldChangePrintInfo(newPrintInfo)
    @documentView.resetMargins(newPrintInfo)
    return true
  end
end
